<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>测试API</title>
<script type="text/javascript">
Handlebars.registerHelper("ifnull", function(value) {
	if (value == 0||value) {
		return value;
	}
    return " ";
});
jQuery(function($){
	function refresh(){
	    $.get(ctx+"/web/user/ali/list.json").success(function(json) {
	    	$(".tmp").remove();
	    	var html = $("#user-tpl").html();
	        var tpl = Handlebars.compile(html);
	        $("#user-tpl").after(tpl(json.d));
	        
	        $(".am-icon-trash-o").click(function() {
	            $tr = $(this).closest("tr");
	            var uid = $tr.find("td:eq(1)").html().trim();
	            $.getJSON(ctx+"/web/user/ali/delete.json?uid=" + uid,function(json) {
	                if (json.c == 0) {
	                    alert("删除成功 !");
	                    refresh();
	                } else {
	                    alert("删除失败,code:" + json.c);
	                }
	            });
	        });
	    });
		
	}
	refresh();
});
</script>
<style type="text/css">
.avatar {
	width: 28px;
	height: 28px;
}

.presence {
	width: 16px;
	height: 16px;
	border: 0
}
</style>
</head>
<body>
	<div class="admin-content">
<!-- 		<div class="am-container "> -->
		<div class="am-g">
			<div class="am-u-sm-12">
				<table
					class="am-table am-table-bd am-table-striped admin-content-table">
					<thead>
						<tr>
							<th>头像</th>
							<th>UID</th>
							<th>手机号</th>
							<th>昵称</th>
							<th>在线状态</th>
							<th>会员等级</th>
							<th>管理</th>
						</tr>
					</thead>
					<tbody>
					<script id="user-tpl" type="text/x-handlebars-template">
					{{#each this}}
  						<tr class="tmp">
							<td>{{#if avatar}}<img class="avatar" src="{{avatar}}">{{else}}&nbsp;{{/if}}</td>
							<td>{{id}}</td>
							<td>{{ifnull phone}}</td>
							<td>{{ifnull nick}}</td>
							{{#if online}}<td><img class="presence" src="${ctxStatic}/images/user-green-16x16.gif"/></td>
								{{else}}<td><img class="presence" src="${ctxStatic}/images/user-clear-16x16.gif"/></td>
							{{/if}}
							<td>{{ifnull lvl}}</td>
							<td>
								<button class="am-btn am-btn-default am-btn-xs am-text-danger am-icon-trash-o"> 删除</button>
							</td>
						</tr>
					{{/each}}
					</script>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</body>
</html>